package com.booksystem.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;

/**
 * <p>
 *   订单编号生成工具类
 * </p>
 * @author 段伟豪
 */
public class OrderNoGeneratorUtil {

    private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");

    /**
     * 生成唯一的订单编号
     * @return 唯一订单编号
     */
    public static String generateOrderNo() {
        LocalDateTime now = LocalDateTime.now();
        String timestampPart = now.format(DATE_FORMATTER);
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        sb.append(timestampPart);
        for (int i = 0; i < 6; i++) {
            sb.append(random.nextInt(10));
        }
        return sb.toString();
    }
}